{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": 3
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python_defaultSpec_1596535581821",
   "display_name": "Python 3.6.6 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fxcmpy import fxcmpy\n",
    "\n",
    "# generate this once you create your demo account\n",
    "# this is fake token, just for demonstration\n",
    "ACCESS_TOKEN = \"8438834e8edaff70ca3db0088a8d6c5c37f51279\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    fxcm_con = fxcmpy(access_token=ACCESS_TOKEN, server=\"demo\")\n",
    "    print(\"Is connected:\", fxcm_con.is_connected())\n",
    "\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "fxcm_con.open_trade(symbol=\"US30\",amount=1,is_buy=True,time_in_force=\"GTC\",order_type=\"AtMarket\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "trade_id = fxcm_con.get_open_trade_ids()[0]\n",
    "print(\"Closing trade:\", trade_id)\n",
    "fxcm_con.close_trade(trade_id=trade_id,amount=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "fxcm_con.open_trade(symbol=\"US30\",amount=1,is_buy=True,time_in_force=\"GTC\",order_type=\"AtMarket\",is_in_pips=True,limit=15,stop=-50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fxcm_con.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}